<?php


namespace app\common\lib;

use app\common\cachemodel\AppIndexAbLogData;
use app\common\cachemodel\Article;
use app\common\cachemodel\Fortune;
use app\common\cachemodel\GoddessArea;
use app\common\cachemodel\GoddessBaseInfo;
use app\common\cachemodel\ZlAdminVip;
use app\common\cachemodel\ZlFortuneUp;
use app\common\cachemodel\ZlGoddessState;
use app\common\model\Recode;
use app\common\model\Slide;
use think\Env;

/**
 * app【配置管理】
 * Class ConfigManage
 * @package app\common\lib
 */
class ConfigManage
{
    /**
     * 获取用户类型
     * @param int $uid
     * @return int 0=>普通用户 ，1=>官方, 2=>女神
     */
    public function innerUser(int $uid)
    {
        if ($uid)
        {
            $adminVipModel = new ZlAdminVip();
            $official = $adminVipModel->getVipInfo(4);
            if (in_array($uid, $official))
            {
                return 1;
            }
            $goddess = $adminVipModel->getVipInfo(5);
            if (in_array($uid, $goddess))
            {
                return 2;
            }
        }
        return 0;

//
//        $official = Env::get('innerUser.official');
//        $goddess = Env::get('innerUser.goddess');
//        if (in_array($uid, ($official ? explode(',', $official) : [])))
//        {
//            return 1;
//        }
//        if (in_array($uid, ($official ? explode(',', $goddess) : [])))
//        {
//            return 2;
//        }
//        return 0;
    }

    /**
     * 获取首页目录配置
     * @param $userInfo
     * @param $headerVersion
     * @param $in_sign
     * @param array $fortune_cache 今日运势数据
     * @return mixed
     * @throws exception\ApiException
     * @throws \Exception
     */
    public static function indexCategory($userInfo, $in_sign, $headerVersion, $fortune_cache = [])
    {
        $isYoung = $userInfo ? $userInfo['young_model'] : false; // 是否是青少年模式
        $fortune_selected_index = 0;//首页运势目录默认选中今日，数组下标
        $article_selected_index = 0;//首页文章目录默认选中，数组下标
        $data['fortune_category'] = null;
        $data['article_category'] = null;

        //用户未登录或没有档案
        if (!$userInfo['id'] || !$userInfo['rid'])
        {
            $fortune_selected_index = 1;//首页运势目录默认选中本周
        }

        //首页运势目录 青少年模式，只有今日，本周
        if ($isYoung)
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '今日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '本周',
                        'need_auth' => 0,
                    ],
                ],
                'content' => null,
            ];
        } else
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '今日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '本周',
                        'need_auth' => 0,
                    ],
                    2 => [
                        'type' => 3,
                        'name' => '本月',
                        'need_auth' => 1,
                    ],
                    3 => [
                        'type' => 4,
                        'name' => '本年',
                        'need_auth' => 1,
                    ],
                    4 => [
                        'type' => 5,
                        'name' => '一生',
                        'need_auth' => 1,
                    ],
                ],
                'content' => null,
            ];
        }
        $data['fortune_category']['selected_index'] = $fortune_selected_index;//默认选中下标
        $fortuneModel = new Fortune();
        switch ($fortune_selected_index)
        {
            case 0:
                if (Util::CheckAppVersion('2.4.2') !== '小')
                {
                    $fortune = $fortuneModel->todayInfoV2($userInfo, $fortune_cache);
                    // 获取运势提升状态 1已提升 0未提升
                    $isFortuneUp = (new ZlFortuneUp())->getFortuneUpStatus((int)$userInfo['rid'], (int)(date('Ymd')));
                    if ($isFortuneUp)
                    {
                        $fortune['today']['fortune_up_status'] = 2;
                    } else
                    {
                        $fortune['today']['fortune_up_status'] = 0;
                        foreach ($fortune['today']['list'] as $item)
                        {
                            if (in_array($item['color'], ['#ffed17', '#ffa536', '#7775ff'], true))
                            {
                                $fortune['today']['fortune_up_status'] = 1;
                                break;
                            }
                        }
                    }
                } else
                {
                    $fortune = $fortuneModel->todayInfo($userInfo, $fortune_cache);
                }
                break;
            case 1:
                $fortune = $fortuneModel->weekInfo($in_sign);
                break;
            case 2:
                $fortune = $fortuneModel->monthInfo($userInfo, $headerVersion);
                break;
            case 3:
                $fortune = $fortuneModel->yearInfo($userInfo, $headerVersion);
                break;
            case 4:
                $fortune = $fortuneModel->reportInfo($userInfo);
                break;
            default:
                $fortune = [];
                break;
        }
        $data['fortune_category']['content'] = $fortune;
        //青少年模式不显示文章
        if (!$isYoung)
        {
            //首页文章目录
            $data['article_category'] = [
                'list' => [
                    0 => [
                        'type' => 2,
                        'name' => '女神动态',
                    ],
                    1 => [
                        'type' => 3,
                        'name' => '互动专区',
                    ],
                    2 => [
                        'type' => 1,
                        'name' => '星文推荐',
                    ],
                ],
                'content' => null,
            ];
            //获取公告信息
            $goddessInfo = (new GoddessBaseInfo())->getInfo(['nickname', 'avatar', 'notice_img1', 'target1', 'link1', 'notice_img2', 'target2', 'link2', 'notice_img3', 'target3', 'link3']);
            $goddessNotice = null;
            switch ($article_selected_index)
            {
                case 0://动态
                    $article = (new ZlGoddessState())->getGoddessStateFromCache($userInfo);
                    if ($goddessInfo['notice_img1'])
                    {
                        $goddessNotice = [
                            'type' => 5,
                            'thumb' => $goddessInfo['notice_img1'] ?? '',
                            'target' => $goddessInfo['target1'] ?? '',
                            'link' => $goddessInfo['link1'] ?? '',
                        ];
                        array_unshift($article['data'], $goddessNotice);
                    }
                    $data['article_category']['state_content'] = $article;
                    break;
                case 1://话题
                    $article = (new GoddessArea())->getThemeData($userInfo['id'], $goddessInfo, 1, 10);
                    if ($goddessInfo['notice_img2'])
                    {
                        $goddessNotice = [
                            'img' => $goddessInfo['notice_img2'] ?? '',
                            'target' => $goddessInfo['target2'] ?? '',
                            'link' => $goddessInfo['link2'] ?? '',
                        ];
                        array_unshift($article['data'], $goddessNotice);
                    }
                    $data['article_category']['area_content'] = $article;
                    break;
                case 2://星文
                    $pageData = (new Article())->getArticleIndexIds($userInfo['id'], 2, 1, 20);
                    $article = $pageData['data'];
                    if ($goddessInfo['notice_img3'])
                    {
                        $goddessNotice = [
                            'type' => 5,
                            'thumb' => $goddessInfo['notice_img3'] ?? '',
                            'target' => $goddessInfo['target3'] ?? '',
                            'link' => $goddessInfo['link3'] ?? '',
                        ];
                        array_unshift($article, $goddessNotice);
                    }
                    $data['article_category']['article_content'] = $article;
                    break;
            }
            $data['article_category']['selected_index'] = $article_selected_index;//默认选中下标
        }
        return $data;
    }

    /**
     * 获取首页目录配置 V2.6.0版本级以后
     * @param $userInfo
     * @param $in_sign
     * @param $headerVersion
     * @param array $fortune_cache
     * @param int $contentType
     * @return mixed
     * @throws exception\ApiException
     */
    public static function indexCategoryV2($userInfo, $in_sign, $headerVersion, $fortune_cache = [], $contentType = 2)
    {
        $isYoung = $userInfo ? $userInfo['young_model'] : false; // 是否是青少年模式
        $fortune_selected_index = 0;//首页运势目录默认选中今日，数组下标
        $data['fortune_category'] = null;
        $data['article_category'] = null;

        //用户未登录或没有档案
        if (!$userInfo['id'] || !$userInfo['rid'])
        {
            $fortune_selected_index = 1;//首页运势目录默认选中本周
        }

        //首页运势目录 青少年模式，只有今日，本周
        if ($isYoung)
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '周',
                        'need_auth' => 0,
                    ],
                ],
                'content' => null,
            ];
        } else
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '周',
                        'need_auth' => 0,
                    ],
                    2 => [
                        'type' => 3,
                        'name' => '月',
                        'need_auth' => 1,
                    ],
                    3 => [
                        'type' => 4,
                        'name' => '年',
                        'need_auth' => 1,
                    ],
                ],
                'content' => null,
            ];
        }
        $data['fortune_category']['selected_index'] = $fortune_selected_index;//默认选中下标
        $fortuneModel = new Fortune();
        switch ($fortune_selected_index)
        {
            case 0:
                if (Util::CheckAppVersion('2.4.2') !== '小')
                {
                    $fortune = $fortuneModel->todayInfoV2($userInfo, $fortune_cache);
                    // 获取运势提升状态 1已提升 0未提升
                    $isFortuneUp = (new ZlFortuneUp())->getFortuneUpStatus((int)$userInfo['rid'], (int)(date('Ymd')));
                    if ($isFortuneUp)
                    {
                        $fortune['today']['fortune_up_status'] = 2;
                    } else
                    {
                        $fortune['today']['fortune_up_status'] = 0;
                        foreach ($fortune['today']['list'] as $item)
                        {
                            if (in_array($item['color'], ['#ffed17', '#ffa536', '#7775ff'], true))
                            {
                                $fortune['today']['fortune_up_status'] = 1;
                                break;
                            }
                        }
                    }
                } else
                {
                    $fortune = $fortuneModel->todayInfo($userInfo, $fortune_cache);
                }
                break;
            case 1:
                $fortune = $fortuneModel->weekInfo($in_sign);
                break;
            case 2:
                $fortune = $fortuneModel->monthInfo($userInfo, $headerVersion);
                break;
            case 3:
                $fortune = $fortuneModel->yearInfo($userInfo, $headerVersion);
                break;
            default:
                $fortune = [];
                break;
        }
        $data['fortune_category']['content'] = $fortune;
        //青少年模式不显示文章
        if (!$isYoung)
        {
            //首页文章目录
            $data['article_category'] = [
                'article_content' => null,
                'state_content' => null,
            ];
            //获取公告信息
            $goddessInfo = (new GoddessBaseInfo())->getInfo(['id', 'nickname', 'avatar', 'notice_img1', 'target1', 'link1', 'notice_img2', 'target2', 'link2', 'notice_img3', 'target3', 'link3']);
            $goddessNotice = null;
            switch ($contentType)
            {
                case 1://星文
                    $pageData = (new Article())->getArticleIndexIds($userInfo['id'], 2, 1, 20);
                    $article = $pageData['data'];
                    if ($goddessInfo['notice_img3'])
                    {
                        $goddessNotice = [
                            'type' => 5,
                            'thumb' => $goddessInfo['notice_img3'] ?? '',
                            'target' => $goddessInfo['target3'] ?? '',
                            'link' => $goddessInfo['link3'] ?? '',
                        ];
                        array_unshift($article, $goddessNotice);
                    }
                    $data['article_category']['article_content'] = $article;
                    break;
                case 2://动态
                    $article = (new ZlGoddessState())->getGoddessStateFromCache($userInfo, 1);
                    if (Util::CheckAppVersion('2.6.0') !== '小')
                    {
                        self::articleStateAdvertisementData($article['data'], $article['per_page'], $article['current_page']);
                    } else
                    {
                        if (!empty($goddessInfo['notice_img1']))
                        {
                            $img_data = getimagesize(Env::get('host.photo') . $goddessInfo['notice_img1']);
                            $goddessNotice = [
                                'id' => $goddessInfo['id'],
                                'type' => 5,
                                'title' => $goddessInfo['title1'] ?? '',
                                'thumb' => $goddessInfo['notice_img1'] ?? '',
                                'thumb_width' => $img_data[0] ?? 0,
                                'thumb_height' => $img_data[1] ?? 0,
                                'target' => $goddessInfo['target1'] ?? '',
                                'link' => $goddessInfo['link1'] ?? '',
                                'data_type' => 2,
                            ];
                            array_unshift($article['data'], $goddessNotice);
                        }
                    }

                    $data['article_category']['state_content'] = $article;
                    break;
            }
        }
        return $data;
    }

    /**
     * 获取首页目录配置 V2.9.3版本级以后
     * @param $userInfo
     * @param $in_sign
     * @param $headerVersion
     * @param array $fortune_cache
     * @param int $contentType
     * @return mixed
     * @throws exception\ApiException
     */
    public static function indexCategoryV3($userInfo, $in_sign, $headerVersion, $fortune_cache = [], $contentType = 2)
    {
        $isYoung = $userInfo ? $userInfo['young_model'] : false; // 是否是青少年模式
        $fortune_selected_index = 0;//首页运势目录默认选中今日，数组下标
        $data['fortune_category'] = null;
        $data['article_category'] = null;

        //首页运势目录 青少年模式，只有今日，本周
        if ($isYoung && $userInfo && $userInfo['rid'])
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '周',
                        'need_auth' => 0,
                    ],
                ],
                'content' => null,
            ];
        } else
        {
            $data['fortune_category'] = [
                'list' => [
                    0 => [
                        'type' => 1,
                        'name' => '日',
                        'need_auth' => 1,
                    ],
                    1 => [
                        'type' => 2,
                        'name' => '周',
                        'need_auth' => 0,
                    ],
                    2 => [
                        'type' => 3,
                        'name' => '月',
                        'need_auth' => 1,
                    ],
                    3 => [
                        'type' => 4,
                        'name' => '年',
                        'need_auth' => 1,
                    ],
                ],
                'content' => null,
            ];
        }
        $data['fortune_category']['selected_index'] = $fortune_selected_index;//默认选中下标
        $fortuneModel = new Fortune();
        $isAstroFortuneArticle = $userInfo && $userInfo['rid'] ? false : true; //是否是星座运势文章
        switch ($fortune_selected_index)
        {
            case 0:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->todayArticle($in_sign);
                } else
                {
                    $fortune = $fortuneModel->todayInfoV2($userInfo, $fortune_cache);
                    // 获取运势提升状态 1已提升 0未提升
                    $isFortuneUp = (new ZlFortuneUp())->getFortuneUpStatus((int)$userInfo['rid'], (int)(date('Ymd')));
                    if ($isFortuneUp)
                    {
                        $fortune['today']['fortune_up_status'] = 2;
                    } else
                    {
                        $fortune['today']['fortune_up_status'] = 0;
                        foreach ($fortune['today']['list'] as $item)
                        {
                            if (in_array($item['color'], ['#ffed17', '#ffa536', '#7775ff'], true))
                            {
                                $fortune['today']['fortune_up_status'] = 1;
                                break;
                            }
                        }
                    }
                }
                break;
            case 1:
                $fortune = $fortuneModel->weekInfo2($in_sign);
                break;
            case 2:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->monthArticle($in_sign);
                } else
                {
                    $fortune = $fortuneModel->monthInfo($userInfo, $headerVersion);
                }
                break;
            case 3:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->yearArticle($in_sign);

                } else
                {
                    $fortune = $fortuneModel->yearInfo($userInfo, $headerVersion);
                }
                break;
            default:
                $fortune = [];
                break;
        }
        $data['fortune_category']['content'] = $fortune;
        //青少年模式不显示文章
        if (!$isYoung)
        {
            //首页文章目录
            $data['article_category'] = [
                'article_content' => null,
                'state_content' => null,
            ];
            //获取公告信息
            $goddessInfo = (new GoddessBaseInfo())->getInfo(['id', 'nickname', 'avatar', 'notice_img1', 'target1', 'link1', 'notice_img2', 'target2', 'link2', 'notice_img3', 'target3', 'link3']);
            $goddessNotice = null;
            switch ($contentType)
            {
                case 1://星文
                    $pageData = (new Article())->getArticleIndexIds($userInfo['id'], 2, 1, 20);
                    $article = $pageData['data'];
                    if ($goddessInfo['notice_img3'])
                    {
                        $goddessNotice = [
                            'type' => 5,
                            'thumb' => $goddessInfo['notice_img3'] ?? '',
                            'target' => $goddessInfo['target3'] ?? '',
                            'link' => $goddessInfo['link3'] ?? '',
                        ];
                        array_unshift($article, $goddessNotice);
                    }
                    $data['article_category']['article_content'] = $article;
                    break;
                case 2://动态
                    $article = (new ZlGoddessState())->getGoddessStateFromCache($userInfo, 1);
                    if (Util::CheckAppVersion('2.6.0') !== '小')
                    {
                        self::articleStateAdvertisementData($article['data'], $article['per_page'], $article['current_page']);
                    } else
                    {
                        if (!empty($goddessInfo['notice_img1']))
                        {
                            $img_data = getimagesize(Env::get('host.photo') . $goddessInfo['notice_img1']);
                            $goddessNotice = [
                                'id' => $goddessInfo['id'],
                                'type' => 5,
                                'title' => $goddessInfo['title1'] ?? '',
                                'thumb' => $goddessInfo['notice_img1'] ?? '',
                                'thumb_width' => $img_data[0] ?? 0,
                                'thumb_height' => $img_data[1] ?? 0,
                                'target' => $goddessInfo['target1'] ?? '',
                                'link' => $goddessInfo['link1'] ?? '',
                                'data_type' => 2,
                            ];
                            array_unshift($article['data'], $goddessNotice);
                        }
                    }

                    $data['article_category']['state_content'] = $article;
                    break;
            }
        }
        return $data;
    }

    /**
     * 获取首页目录配置 V2.9.3版本级以后
     * @param $userInfo
     * @param $in_sign
     * @param $headerVersion
     * @param array $fortune_cache
     * @param int $contentType
     * @return mixed
     * @throws exception\ApiException
     */
    public static function indexCategoryV4($userInfo, $in_sign, $headerVersion, $fortune_cache = [], $contentType = 2)
    {
        $isYoung = $userInfo ? $userInfo['young_model'] : false; // 是否是青少年模式
        $fortune_selected_index = 0;//首页运势目录默认选中今日，数组下标
        $data['fortune_category'] = null;
        $data['article_category'] = null;

        //首页运势目录 青少年模式，只有今日，本周
        if (($isYoung && $userInfo && $userInfo['rid']) || Util::AppIsPassShowV1())
        {
            if (Util::CheckAppVersion('2.10.4') !== '小')
            {
                if ($userInfo && $userInfo['rid'] && Util::IsHuaweiOrHonorOrOppo() && Util::CheckAppVersion('2.14.0') !== '小')
                {
                    $data['fortune_category'] = [
                        'list' => [
                            0 => [
                                'type' => 1,
                                'name' => '日',
                                'need_auth' => 1,
                            ],
                            1 => [
                                'type' => 2,
                                'name' => '周',
                                'need_auth' => 0,
                            ],
                            2 => [
                                'type' => 3,
                                'name' => '月',
                                'need_auth' => 0,
                            ],
                            3 => [
                                'type' => 4,
                                'name' => '年',
                                'need_auth' => 0,
                            ],
                        ],
                        'content' => null,
                    ];
                    $fortune_selected_index = 0;//默认选中本周
                } else
                {
                    $data['fortune_category'] = [
                        'list' => [
                            0 => [
                                'type' => 2,
                                'name' => '周',
                                'need_auth' => 0,
                            ], 1 => [
                                'type' => 3,
                                'name' => '月',
                                'need_auth' => 0,
                            ],
                            2 => [
                                'type' => 4,
                                'name' => '年',
                                'need_auth' => 0,
                            ],
                        ],
                        'content' => null,
                    ];
                    $fortune_selected_index = 1;//默认选中本周
                }
            } else
            {
                $data['fortune_category'] = [
                    'list' => [
                        0 => [
                            'type' => 1,
                            'name' => '日',
                            'need_auth' => 1,
                        ],
                        1 => [
                            'type' => 2,
                            'name' => '周',
                            'need_auth' => 0,
                        ],
                    ],
                    'content' => null,
                ];
            }
        } else
        {
            if (!isset($userInfo['rid']) || (!$userInfo['rid'] && Util::CheckAppVersion('2.10.4') !== '小'))
            {
                $data['fortune_category'] = [
                    'list' => [
                        0 => [
                            'type' => 2,
                            'name' => '周',
                            'need_auth' => 0,
                        ], 1 => [
                            'type' => 3,
                            'name' => '月',
                            'need_auth' => 0,
                        ],
                        2 => [
                            'type' => 4,
                            'name' => '年',
                            'need_auth' => 0,
                        ],
                    ],
                    'content' => null,
                ];
                $fortune_selected_index = 1;//默认选中本周
            } else
            {
                $data['fortune_category'] = [
                    'list' => [
                        0 => [
                            'type' => 1,
                            'name' => '日',
                            'need_auth' => 1,
                        ],
                        1 => [
                            'type' => 2,
                            'name' => '周',
                            'need_auth' => 0,
                        ],
                        2 => [
                            'type' => 3,
                            'name' => '月',
                            'need_auth' => 1,
                        ],
                        3 => [
                            'type' => 4,
                            'name' => '年',
                            'need_auth' => 1,
                        ],
                    ],
                    'content' => null,
                ];
            }
        }
        $data['fortune_category']['selected_index'] = 0;//默认选中下标
        $fortuneModel = new Fortune();
        $isAstroFortuneArticle = $userInfo && $userInfo['rid'] ? false : true; //是否是星座运势文章
        switch ($fortune_selected_index)
        {
            case 0:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->todayArticle($in_sign);
                } else
                {
                    $style = 1;
                    // if (Util::CheckAppVersion('2.14.0') !== '小')
                    // {
                    //     $style = $userInfo['id'] % 2 === 0 ? 2 : 1;
                    //     // AB测试 访问日志
                    //     (new AppIndexAbLogData())->setAbLog($userInfo['id'], $style, 1);
                    // }
                    if ($style === 1)
                    {
                        $fortune = $fortuneModel->todayInfoV2($userInfo, $fortune_cache, 3);
                        // 获取运势提升状态 1已提升 0未提升
                        $isFortuneUp = (new ZlFortuneUp())->getFortuneUpStatus((int)$userInfo['rid'], (int)(date('Ymd')));
                        if ($isFortuneUp)
                        {
                            $fortune['today']['fortune_up_status'] = 2;
                        } else
                        {
                            $fortune['today']['fortune_up_status'] = 0;
                            foreach ($fortune['today']['list'] as $item)
                            {
                                if (in_array($item['color'], ['#ffed17', '#ffa536', '#7775ff'], true))
                                {
                                    $fortune['today']['fortune_up_status'] = 1;
                                    break;
                                }
                            }
                        }
                    } else
                    {
                        $fortune = $fortuneModel->todayInfoB1($userInfo, $fortune_cache);
                    }
                }
                break;
            case 1:
                $fortune = $fortuneModel->weekInfo2($in_sign);
                break;
            case 2:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->monthArticle($in_sign);
                } else
                {
                    $fortune = $fortuneModel->monthInfo($userInfo, $headerVersion);
                }
                break;
            case 3:
                if ($isAstroFortuneArticle)
                {
                    $fortune = $fortuneModel->yearArticle($in_sign);

                } else
                {
                    $fortune = $fortuneModel->yearInfo($userInfo, $headerVersion);
                }
                break;
            default:
                $fortune = [];
                break;
        }
        $data['fortune_category']['content'] = $fortune;
        //青少年模式不显示文章
        if (!$isYoung)
        {
            //首页文章目录
            $data['article_category'] = [
                'article_content' => null,
                'state_content' => null,
            ];
            //获取公告信息
            $goddessInfo = (new GoddessBaseInfo())->getInfo(['id', 'nickname', 'avatar', 'notice_img1', 'target1', 'link1', 'notice_img2', 'target2', 'link2', 'notice_img3', 'target3', 'link3']);
            $goddessNotice = null;
            switch ($contentType)
            {
                case 1://星文
                    $pageData = (new Article())->getArticleIndexIds($userInfo['id'], 2, 1, 20);
                    $article = $pageData['data'];
                    if ($goddessInfo['notice_img3'])
                    {
                        $goddessNotice = [
                            'type' => 5,
                            'thumb' => $goddessInfo['notice_img3'] ?? '',
                            'target' => $goddessInfo['target3'] ?? '',
                            'link' => $goddessInfo['link3'] ?? '',
                        ];
                        array_unshift($article, $goddessNotice);
                    }
                    $data['article_category']['article_content'] = $article;
                    break;
                case 2://动态
                    $article = (new ZlGoddessState())->getGoddessStateFromCache($userInfo, 1);
                    if (Util::CheckAppVersion('2.6.0') !== '小')
                    {
                        self::articleStateAdvertisementData($article['data'], $article['per_page'], $article['current_page']);
                    } else
                    {
                        if (!empty($goddessInfo['notice_img1']))
                        {
                            $img_data = getimagesize(Env::get('host.photo') . $goddessInfo['notice_img1']);
                            $goddessNotice = [
                                'id' => $goddessInfo['id'],
                                'type' => 5,
                                'title' => $goddessInfo['title1'] ?? '',
                                'thumb' => $goddessInfo['notice_img1'] ?? '',
                                'thumb_width' => $img_data[0] ?? 0,
                                'thumb_height' => $img_data[1] ?? 0,
                                'target' => $goddessInfo['target1'] ?? '',
                                'link' => $goddessInfo['link1'] ?? '',
                                'data_type' => 2,
                            ];
                            array_unshift($article['data'], $goddessNotice);
                        }
                    }

                    $data['article_category']['state_content'] = $article;
                    break;
            }
        }
        return $data;
    }

    /**
     * 获取女神动态广告数据
     * @param $article
     * @param $limit
     * @param $page
     * @throws exception\ApiException
     */
    public static function articleStateAdvertisementData(&$article, $limit, $page): void
    {
        $adInfos = (new Slide())->getGoddessStateAdv();
        $appIcon = config('app.icon');
        $resAdvInfo = [];
        foreach ($adInfos as $advItem)
        {
            $photo = is_string($advItem['photo']) ? unserialize($advItem['photo']) : $advItem['photo'];
            if ($photo)
            {
                $temp = explode('|', $photo[0]);
                $thumb = $temp[0] ?? '';
                $temp1 = explode('*', $temp[1]);
                $thumb_width = (int)($temp1[0] ?? 0);
                $thumb_height = (int)($temp1[1] ?? 0);
            }

            $resAdvInfo[$advItem['sort']] = [
                'id' => $advItem['id'],
                'title' => $advItem['name'],
                'thumb' => $thumb ?? '',
                'thumb_width' => $thumb_width ?? 0,
                'thumb_height' => $thumb_height ?? 0,
                'data_type' => 2,
                'type' => 10,
                'target' => $advItem['target'],
                'link' => htmlspecialchars_decode($advItem['link']),
                'avatar_adorn' => '',
                'name' => $advItem['description'],
                'avatar' => $appIcon,
            ];
        }
        $start = ($page - 1) * $limit + 1;
        $end = $page * $limit;

        foreach ($resAdvInfo as $index => $item)
        {
            if ($index >= $start && $index <= $end)
            {
                $index = $index % 10;
                array_splice($article, $index, 0, [$item]);
            } elseif ($index == 0 && $page === 1)
            {
                array_unshift($article, $item);
            }
        }
    }

    /**
     * 报告商品图片（图片分为，长图和短图）
     * @param $type 1=>app,2=>mini
     * @return mixed
     */
    public static function natalReportGoodImage($type = 1)
    {
        if ($type === 1)
        {
            $data['large_goods'] = ['dating'];//, 'academic'
            $data['large'] = [
                'feelings' => '/test/natal_report/large_feelings.png?v=1590397412',
                'dating' => '/test/natal_report/large_dating_new.png',// 婚姻报告new图
                'money' => '/test/natal_report/large_money.png',
                'carrer' => '/test/natal_report/large_carrer.png',
                'academic' => '/test/natal_report/large_academic2.png?v=20201210',// 学业报告限时9折图片
            ];
            $data['small'] = [
                'feelings' => '/test/natal_report/small_feelings.png', // 恋爱
                'dating' => '/test/natal_report/small_dating.png', //婚姻
                'money' => '/test/natal_report/small_money.png', // 财富
                'carrer' => '/test/natal_report/small_carrer.png', // 事业
                'academic' => '/test/natal_report/small_academic.png', // 学业
            ];
            $data['large_active'] = [
                'feelings' => '/test/natal_report/large_feelings.png?v=1590397412',
                'dating' => '/test/natal_report/large_dating.png',
                'money' => '/test/natal_report/large_money.png',
                'carrer' => '/test/natal_report/large_carrer.png',
                'academic' => '/test/natal_report/large_academic2.png?v=20201210',// 学业报告限时9折图片
            ];
            $data['small_active'] = [
                'feelings' => '/test/natal_report/small_feelings.png', // 恋爱
                'dating' => '/test/natal_report/small_dating.png', //婚姻
                'money' => '/test/natal_report/small_money.png', // 财富
                'carrer' => '/test/natal_report/small_carrer.png', // 事业
                'academic' => '/test/natal_report/small_academic.png', // 学业
            ];
            $data['astro_info2'] = [   // v2.9.0   星座信息
                'feelings' => '/test/natal_report/v1/feelings.png', // 恋爱
                'dating' => '/test/natal_report/v1/dating.png', //婚姻
                'money' => '/test/natal_report/v1/money.png', // 财富
                'carrer' => '/test/natal_report/v1/carrer.png', // 事业
                'academic' => '/test/natal_report/v1/academic.png', // 学业
            ];
        } else
        {
            $data['large_goods'] = ['academic', 'feelings'];
            $data['large'] = [
                'feelings' => '/test/natal_report/mini/large_feelings.png',
                'dating' => '/test/natal_report/mini/large_dating.png',
                'money' => '/test/natal_report/mini/large_money.png',
                'carrer' => '/test/natal_report/mini/large_carrer.png',
                'academic' => '/test/natal_report/mini/large_academic.png?v=20200625',
            ];
            $data['small'] = [
                'feelings' => '/test/natal_report/mini/small_feelings.png', // 恋爱
                'dating' => '/test/natal_report/mini/small_dating.png', //婚姻
                'money' => '/test/natal_report/mini/small_money.png', // 财富
                'carrer' => '/test/natal_report/mini/small_carrer.png', // 事业
                'academic' => '/test/natal_report/mini/small_academic.png', // 学业
            ];
            $data['large_active'] = [
                'feelings' => '/test/natal_report/large_feelings.png?v=1590397412',
                'dating' => '/test/natal_report/large_dating.png',
                'money' => '/test/natal_report/large_money.png',
                'carrer' => '/test/natal_report/large_carrer.png',
                'academic' => '/test/natal_report/large_academic.png',
            ];
            $data['small_active'] = [
                'feelings' => '/test/natal_report/small_feelings.png', // 恋爱
                'dating' => '/test/natal_report/small_dating.png', //婚姻
                'money' => '/test/natal_report/small_money.png', // 财富
                'carrer' => '/test/natal_report/small_carrer.png', // 事业
                'academic' => '/test/natal_report/small_academic.png', // 学业
            ];
        }
        return $data;
    }

    /**
     * 获取精简版报告图片
     * @return array
     */
    public static function simNatalReportGoodImage(): array
    {
        $data['large'] = [
            'feelings' => '/test/natal_report/mini_tt/large_feelings.png', // 恋爱
            'dating' => '/test/natal_report/mini_tt/large_dating.png', //婚姻
            'money' => '/test/natal_report/mini_tt/large_money.png', // 财富
            'carrer' => '/test/natal_report/mini_tt/large_carrer.png', // 事业
            'academic' => '/test/natal_report/mini_tt/large_academic.png?v=20200625', // 学业
        ];
        $data['small'] = [
            'feelings' => '/test/natal_report/mini_tt/small_feelings.png', // 恋爱
            'dating' => '/test/natal_report/mini_tt/small_dating.png', //婚姻
            'money' => '/test/natal_report/mini_tt/small_money.png', // 财富
            'carrer' => '/test/natal_report/mini_tt/small_carrer.png', // 事业
            'academic' => '/test/natal_report/mini_tt/small_academic.png', // 学业
        ];

        return $data;
    }
}
